package com.itheima.advance.reflect.demo02;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo02 {

    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {

        Class studentClass = Class.forName("com.itheima.advance.reflect.demo02.Student");

        Constructor declaredConstructor = studentClass.getDeclaredConstructor();
        Student student = (Student) declaredConstructor.newInstance();
        System.out.println(student);

        Constructor declaredConstructor1 = studentClass.getDeclaredConstructor(String.class, int.class);
        Student student1 = (Student) declaredConstructor1.newInstance("蓝湛", 15);
        System.out.println(student1);
        System.out.println(student == student1);

        Constructor declaredConstructor2 = studentClass.getDeclaredConstructor(String.class);
        declaredConstructor2.setAccessible(true);
        Student student2 = (Student) declaredConstructor2.newInstance("魏婴");
        System.out.println(student2);

    }
}
